﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine.Utils;
using PloobsEngine.SceneControl;


namespace PloobsEngine.Light
{
    public class PointLight : DeferredLight
    {
        /// <summary>
        /// Serialization 
        /// </summary>
        public PointLight()
        {
        }

        /// <summary>
        /// Point Light
        /// </summary>
        /// <param name="lightPosition">Position in World</param>
        /// <param name="color">Color</param>
        /// <param name="lightRadius">Radius</param>
        /// <param name="lightIntensity">Intensity </param>
        public PointLight(Vector3 lightPosition, Color color, float lightRadius, float lightIntensity)
        {
            this.lightPosition = lightPosition;
            this.color = color;
            this.lightRadius = lightRadius;
            this.lightIntensity = lightIntensity;            
        }

        public override void Serialize(System.Xml.XmlTextWriter textWriter)
        {
            SerializerHelper.SerializeBaseType<int>(getId(), "Id", textWriter);          
            SerializerHelper.SerializeVector3(LightPosition, "LightPosition", textWriter);
            SerializerHelper.SerializeVector3(Color.ToVector3(), "Color", textWriter);
            SerializerHelper.SerializeBaseType<float>(LightRadius, "LightRadius", textWriter);
            SerializerHelper.SerializeBaseType<float>(LightIntensity, "LightIntensity", textWriter);
            SerializerHelper.SerializeBaseType<LightType>(LightType, "LightType", textWriter);

        }
        public override void DeSerialize(System.Xml.XmlNode node,EngineStuff engine,IWorld world)
        {
            this.setId(SerializerHelper.DeserializeBaseType<int>("Id", node));
            lightRadius= SerializerHelper.DeserializeBaseType<float>("LightRadius", node);
            lightIntensity = SerializerHelper.DeserializeBaseType<float>("LightIntensity", node);
            Color = new Color(SerializerHelper.DeserializeVector3("Color", node));
            lightPosition= SerializerHelper.DeserializeVector3("LightPosition", node);            
        }

        protected Vector3 lightPosition;

        public virtual Vector3 LightPosition
        {
            get { return lightPosition; }
            set { lightPosition = value; }
        }        
        protected float lightRadius;

        public float LightRadius
        {
            get { return lightRadius; }
            set { lightRadius = value; }
        }
        protected float lightIntensity;

        public float LightIntensity
        {
            get { return lightIntensity; }
            set { lightIntensity = value; }
        }

        protected bool usePointLightQuadraticAttenuation = false;

        public bool UsePointLightQuadraticAttenuation
        {
            get { return usePointLightQuadraticAttenuation; }
            set { usePointLightQuadraticAttenuation = value; }
        }

        #region ILight Members

        public override LightType LightType
        {
            get { return LightType.Deferred_Point; }
        }

        #endregion
    }
}
